package com.wayhome.srpingbootmybatis.doctor.service;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSONObject;
import com.wayhome.srpingbootmybatis.doctor.entity.DrScoreOptinsDTO;
import com.wayhome.srpingbootmybatis.doctor.mapper.ImsDocMapper;
import com.wayhome.srpingbootmybatis.mbs.expertimport.dto.ExpertTemplate;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class DrScoreOptinsImptListener extends AnalysisEventListener<DrScoreOptinsDTO> {


    public List<DrScoreOptinsDTO> list = new ArrayList<>();

    private ImsDocMapper docMapper;

    public DrScoreOptinsImptListener (ImsDocMapper docMapper) {
        this.docMapper = docMapper;
    }

    public List<DrScoreOptinsDTO> getList() {
        return list;
    }

    @Override
    public void invoke(DrScoreOptinsDTO drScoreOptinsDTO, AnalysisContext analysisContext) {
        log.info("单据查询清算经办机构区划流程开始处理数据===》{}", JSONObject.toJSONString(drScoreOptinsDTO));
        String docId = drScoreOptinsDTO.getDocId();
        log.info("docId======{}", docId);
        String replaceIms = docId.replace("ims", "");
        log.info("replaceIms======{}", replaceIms);
        String clrOptins = "";
        if (replaceIms.contains("β")) {
            clrOptins = docMapper.queryDocClrOptinsByDocId(replaceIms);
        }else {
            docId = docMapper.qeuryDocIdByDocSusptId(replaceIms);
            clrOptins = docMapper.queryDocClrOptinsByDocId(docId);

        }
        log.info("clrOptins======{}", replaceIms);
        drScoreOptinsDTO.setClrOptions(clrOptins);
        drScoreOptinsDTO.setDocId(docId);
        list.add(drScoreOptinsDTO);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        log.info("数据处理完成 共{},条数据", list.size());
    }

}
